package com.sky.controller;


import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.ISetmealService;
import com.sky.service.impl.SetmealServiceImpl;
import com.sky.vo.SetmealVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 套餐 前端控制器
 * </p>
 *
 * @author gcl
 * @since 2024-07-02
 */
@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Autowired
    private ISetmealService iSetmealService;

    @GetMapping("/page")
    public Result  getSetmealPage(SetmealPageQueryDTO dto){
        PageResult setmael = iSetmealService.getSetmealPageList(dto);
        return Result.success(setmael);
    }

    @PostMapping
    public Result addSetmeal(@RequestBody SetmealDTO dto){
        iSetmealService.addSetmeal(dto);
        return Result.success();
    }

    @PutMapping
    public Result updateSetmeal(@RequestBody SetmealDTO dto){
        iSetmealService.updateSetmeal(dto);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getSetmealById(@PathVariable("id") Long id){
       SetmealVO setmealVO=  iSetmealService.getSetmealById(id);
       return Result.success(setmealVO);
    }

    @PostMapping("/status/{status}")
    public Result updateSetmealStatus(@PathVariable("status") Integer status,@RequestParam("id") Long id){
        iSetmealService.updateSetmealStatus(status,id);
        return Result.success();
    }

    @DeleteMapping
    public Result deleteSetmealById(@RequestParam("ids") List<Long> ids){
        iSetmealService.removeByIds(ids);
        return Result.success();
    }
}
